<?php
include("../models/webconfig.php");
include("../models/class.connection.php");
include("../models/entities/class.OrderEntity.php");
include("../models/repositories/class.OrderRepository.php");
include("../library/library.pager.php");
$orderRepository = new OrderRepository();
$totalRecords = 0;
$currentPage = 1;
$itemsPerPage = 5;
$pageSize = 5; //Số items thực tế / trang hiện hành
if (isset($_GET['page'])) {
    if (is_numeric($_GET['page']))
        $currentPage = $_GET['page'];
}
$result = $orderRepository->GetPager($currentPage, $itemsPerPage, $totalRecords);
$generateLink = GenerateLink($totalRecords, $pageSize, $itemsPerPage, $currentPage);
$index = 0;
?>

<div class="loading"></div>

<table id="lstOrders" cellspacing="0">
    <tr>
        <td class="title">STT</td>
        <td class="title">Mã ĐH</td>
        <td class="title">Tên KH</td>
        <td class="title">Email</td>
        <td class="title">Phone</td>
        <td class="title">Thời gian đặt hàng</td>
        <td class="title">Thời gian giao hàng</td>
        <td class="title">Trạng thái</td>
        <td class="title" colspan="2">Chức năng</td>
    </tr>
    <?php if (count($result) > 0) {
    ?>
    <?php for ($i = 0; $i < count($result); $i++) {
            $index++; ?>
    <?php if ($result[$i]->Checked_b == 0) {
    ?>
                <tr id="tr-<?php echo($result[$i]->ID_i); ?>">
                    <td style="width: 49px"><?php echo($index); ?></td>
                    <td><?php echo($result[$i]->ID_i); ?></td>
                    <td><?php echo($result[$i]->CustomerName_s); ?></td>
                    <td><?php echo($result[$i]->Email_s); ?></td>
                    <td><?php echo($result[$i]->Phone_s); ?></td>
                    <td><?php echo(substr($result[$i]->OrderTime_dt, 0, 10)); ?></td>
                    <td><?php echo(substr($result[$i]->DeliveryTime_dt, 0, 10)); ?></td>
                    <td><input class="checked" orderId="<?php echo($result[$i]->ID_i); ?>" type="checkbox" />
                    </td>
                    <td><a href="#" onclick="return false;" class="detail" orderId="<?php echo($result[$i]->ID_i); ?>">Xem</a></td>
                    <td><a href="#" onclick="return false;" class="delete" orderId="<?php echo($result[$i]->ID_i); ?>">Xóa</a></td>
                </tr>
    <?php } else {
 ?>
                <tr style="background-color: #f0f7fa;" id="tr-<?php echo($result[$i]->ID_i); ?>">
                    <td style="width: 49px"><?php echo($index); ?></td>
                    <td><?php echo($result[$i]->ID_i); ?></td>
                    <td><?php echo($result[$i]->CustomerName_s); ?></td>
                    <td><?php echo($result[$i]->Email_s); ?></td>
                    <td><?php echo($result[$i]->Phone_s); ?></td>
                    <td><?php echo(substr($result[$i]->OrderTime_dt, 0, 10)); ?></td>
                    <td><?php echo(substr($result[$i]->DeliveryTime_dt, 0, 10)); ?></td>
                    <td><input class="checked" orderId="<?php echo($result[$i]->ID_i); ?>" type="checkbox" checked="checked"/>
                    </td>
                    <td><a href="#" onclick="alert('Vao ham');" class="detail" orderId="<?php echo($result[$i]->ID_i); ?>">Xem</a></td>
                    <td><a href="#" onclick="return false;" class="delete" orderId="<?php echo($result[$i]->ID_i); ?>">Xóa</a></td>
                </tr>
<?php } ?>

    <?php } ?>
<?php } ?>
</table>
<div class="pagination pagination-left">
    <div class="results">
        <span>
            Kết quả từ <?php echo (($currentPage - 1) * $itemsPerPage + (count($result) > 0 ? 1 : 0)); ?> - <?php echo (($currentPage - 1) * $itemsPerPage + count($result)); ?> của <?php echo($totalRecords); ?>
        </span>
    </div>
    <ul class="pager"><?php echo $generateLink ?></ul>
</div>